package com.maven.front.service.manageArticle;

import com.maven.front.bean.EduArticle;
import com.maven.front.bean.EduArticleContent;
import com.maven.front.bean.EduTeacher;
import com.maven.front.bean.Result;
import com.maven.front.dto.EduArticleDto;
import com.maven.front.mapper.EduArticleContentMapper;
import com.maven.front.mapper.EduArticleMapper;

import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

import java.util.List;


@Service
public class ArticleService {

    @Autowired
    private EduArticleMapper eduArticleMapper;
    @Resource
    private EduArticleContentMapper eduArticleContentMapper;



    public List<EduArticle> Managerlist(){
        List<EduArticle> list=eduArticleMapper.Managerlist(null);
        if(CollectionUtils.isEmpty(list)){
            return null;
        }else {
            return list;
        }
    }


    public int update(EduArticleDto eduArticleDto){
        int res=eduArticleMapper.updateByPrimaryKeySelective(eduArticleDto);
        int id=eduArticleDto.getArticleId();
        String content=eduArticleDto.getContent();

        EduArticleContent ec=new EduArticleContent();
        ec.setArticleId(id);
        ec.setContent(content);
        if(res>0){

            int value=eduArticleMapper.update(ec);
            if(value>0){
                return  1;
            }
            return 0;
        }

        return 0;
    }


    public int delect(EduArticle eduArticle){
        int res=eduArticleMapper.updateByPrimaryKeySelective(eduArticle);
        if(res>0){
            return 1;
        }
        else {
            return 0;
        }
    }

    public  List<EduArticle> dimSelect(EduArticleDto eduArticleDto){
        List<EduArticle> list=eduArticleMapper.Managerlist(eduArticleDto);
        if(CollectionUtils.isEmpty(list)){
            return null;
        }
        else {
            return list;
        }


    }

    public EduArticle getById(Integer id){
        EduArticle ea=eduArticleMapper.selectByPrimaryKey(id);
        if(ObjectUtils.isEmpty(ea)){
            return  null;
        }
        else {
            return  ea;
        }
    }

//修改描述
    public int updateselect(EduArticleContent eduArticleContent){
        return this.eduArticleMapper.update(eduArticleContent);
    }

//根据iD
    public EduArticleContent selectId(int id){
        return  this.eduArticleContentMapper.selectid(id);
    }

}
